﻿package mortal.game.view.copy.wine.view
{
    import Message.BroadCast.*;
    import Message.DB.Tables.*;
    import com.gengine.global.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class WinePartyBtnBar extends View
    {
        private var _toastBtn:GLoadingButton;
        private var _wineName:GTextFiled;
        private var _dushu:GTextFiled;
        private static var _instance:WinePartyBtnBar;

        public function WinePartyBtnBar()
        {
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = false;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._toastBtn = UIFactory.gLoadingButton(ResFileConst.ToastBtn, 0, 0, 120, 111, this);
            this._wineName = UIFactory.gTextField("贱男春", -8, 7, 120, 25, this, GlobalStyle.textFormatHuang2.center());
            this._wineName.mouseEnabled = true;
            this._dushu = UIFactory.gTextField("【40°】", 38 - 8, 26, 50, 25, this);
            this._dushu.mouseEnabled = true;
            this._wineName.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._wineName.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._dushu.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._dushu.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this.configEventListener(MouseEvent.CLICK, this.onClickHandler, true);
            this.initBtnState();
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            Dispatcher.addEventListener(EventName.WinePartyWineCollectUpdate, this.updateCollectState);
            return;
        }// end function

        private function removeListeners() : void
        {
            Dispatcher.removeEventListener(EventName.WinePartyWineCollectUpdate, this.updateCollectState);
            return;
        }// end function

        private function initBtnState() : void
        {
            var _loc_1:* = BossConfig.instance.getInfoByCode(GameConst.WinePartyOriginWineBossCode);
            if (_loc_1)
            {
                this._wineName.text = _loc_1.name;
                this._dushu.text = Language.getStringByParam(40986, _loc_1.penetration);
            }
            return;
        }// end function

        private function updateWineInfo() : void
        {
            var _loc_1:* = Cache.instance.copy.wineParty.currCollectWineBoss;
            if (_loc_1)
            {
                this._wineName.text = _loc_1.name;
                this._dushu.text = Language.getStringByParam(40986, _loc_1.penetration);
            }
            else
            {
                this._wineName.text = "";
                this._dushu.text = "";
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            this.x = Global.stage.stageWidth - 450;
            this.y = Global.stage.stageHeight - 200;
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_2:* = Cache.instance.copy.wineParty.currSelToastPerson;
            var _loc_4:Object = {};
            _loc_4["toaster"] = _loc_2;
            _loc_4["wineType"] = _loc_3;
            Dispatcher.dispatchEvent(new DataEvent(EventName.WinePartyStartToast, _loc_4));
            return;
        }// end function

        private function updateCollectState(event:DataEvent) : void
        {
            this.updateWineInfo();
            this._toastBtn.filterEnabled = Cache.instance.copy.wineParty.currCollectWineBoss == null ? (false) : (true);
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._toastBtn.dispose();
            this._wineName.dispose();
            this._dushu.dispose();
            this._toastBtn = null;
            this._wineName = null;
            this._dushu = null;
            this.removeListeners();
            return;
        }// end function

        public static function get instance() : WinePartyBtnBar
        {
            if (_instance == null)
            {
                _instance = new WinePartyBtnBar;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
